DEFINITION MODULE Display;

(* (C) Copyright 1987,1988 Fitted Software Tools. All rights reserved. *)

FROM SYSTEM IMPORT ADDRESS;


VAR displayMode :CARDINAL;              (* initialized to current mode *)
    displayPage :CARDINAL;              (* initialized from current mode *)
    displayAttr :CARDINAL;              (* initialized to 07H *)
    displayLines:CARDINAL;              (* initialized to 25 *)
    displayCols :CARDINAL;              (* initialized from current mode *)
    snowy       :BOOLEAN;               (* wait for retrace on video IO *)
                                        (* init TRUE if displayMode <> 7 *)

(*
    -------------------------------------------------------------
    BIOS interface routines.
    The following procedures do their work through the PC's BIOS.
    -------------------------------------------------------------
*)

PROCEDURE GetDisplayMode( VAR mode, nCols, activePage :CARDINAL );
(*
    Returns current display mode.
*)

PROCEDURE SetDisplayMode( mode :CARDINAL );
(*
    Sets the display mode.
*)

PROCEDURE SetCursorType( start, end :CARDINAL );
(*
    Set the cursor starting and ending lines.
*)

PROCEDURE GetCursorPosition( VAR line :CARDINAL; VAR pos :CARDINAL );
(*
    Returns the current cursor position.
*)

PROCEDURE SetCursorPosition( line :CARDINAL; pos :CARDINAL );
(*
    Moves the cursor to line/pos.
*)

PROCEDURE ScrollUp( n, line1, pos1, line2, pos2 :CARDINAL; attr :CARDINAL );
(*
    Scrolls window up n lines.
     line1, pos1 = top left corner of the window to scroll.
     line2, pos2 = bottom right corner of the window.
     attr is attribute for new blank lines.
     IF n = 0 THEN ClearWindow.
*)

PROCEDURE ScrollDown( n, line1, pos1, line2, pos2 :CARDINAL; attr :CARDINAL );
(*
    Scrolls window down n lines.
*)

PROCEDURE ReadCharAttr( VAR ch :CHAR; VAR attr :CARDINAL );
(*
    Reads the character and attribute under the cursor.
*)

PROCEDURE WriteCharAttr( ch :CHAR; attr :CARDINAL );
(*
    Writes the character and attribute at current cursor location.
    The cursor is not moved.
*)

PROCEDURE WriteChar( ch :CHAR );
(*
    Writes ch at the current cursor location.
*)


(*
    -----------------------------------------------------------------
    The following procedures work within the bowdaries of the current
    window as defined by line0,col0-lineN,colN.
    -----------------------------------------------------------------
*)

VAR
    (* current window coordinates *)
    line0       :CARDINAL;              (* top line, init 0 *)
    col0        :CARDINAL;              (* leftmost col, init 0 *)
    lineN       :CARDINAL;              (* last line in window *)
    colN        :CARDINAL;              (* last col in window *)

PROCEDURE Goto( line, col :CARDINAL );
(*
    moves the cursor to line/pos within the current window
*)

PROCEDURE Write( ch :CHAR );
(*
    Writes the character at the current screen location, using displayAttr,
    and advances the cursor.

    The following control characters are processed:
        BEL, EOL, CR, LF, FF, DEL, BS, HT.
*)

PROCEDURE ClrEOL;
(*
    clear to the end of the line (uses displayAttr)
*)

PROCEDURE ClrEOS;
(*
    clear to the end of the window (uses displayAttr)
*)


(*
    ------------------------------------------------------------
    The following procedures work only in text mode!
    They provide a fast means of updating the screen by writing
    directly to the display adapter's memory.
    ------------------------------------------------------------
*)

TYPE DisplayBuffer = ARRAY [0..24] OF ARRAY [0..79] OF CARDINAL;

VAR
    displayPtr  :POINTER TO DisplayBuffer;  (* loaded at initialization time *)


PROCEDURE DisplayString( s :ARRAY OF CHAR; line, pos :CARDINAL; attr :CARDINAL );
(*
    Writes the string directly into the display buffer.
    line and pos are relative to the current window.

    The cursor is not moved and control characters are not processed.
*)
(*
    end of window related procedures
    --------------------------------
*)


PROCEDURE DisplayLine( line :ARRAY OF CHAR; lineno :CARDINAL; attr :CARDINAL );
(*
    Writes an 80 character line directly into the display buffer.
     attr is the attribute character to be used.
     If length(line) < 80, fill w/ spaces.
*)

PROCEDURE WriteScreen( src, dest :ADDRESS; nWords :CARDINAL );
(*
    Moves src to dest for nWords.
    dest is assumed to be within the display buffer.
    Monitors the vertical retrace signal if snowy = TRUE.
*)

PROCEDURE ReadScreen( src, dest :ADDRESS; nWords :CARDINAL );
(*
    Moves src to dest for nWords.
    src is assumed to be within the display buffer.
    Monitors the vertical retrace signal if snowy = TRUE.
*)

END Display.